// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: Code style modification
// ------------------------------------------------------------------

#ifndef XMLPARSER_XMLENDPOINTPARSER_H_
#define XMLPARSER_XMLENDPOINTPARSER_H_
#include <cstdint>
#include <set>
#include <string>
#include <vector>
#include <xmlparser/XMLParserCommonPart.h>
#include <xmlparser/data/XMLReaderProxyData.h>
#include <xmlparser/data/XMLWriterProxyData.h>
#include <string>

namespace tinyxml2 {
class XMLElement;
class XMLDocument;
}  // namespace tinyxml2

namespace vbsutil {
namespace xmlparser {

class StaticRTPSParticipantInfoPart {
 public:
    StaticRTPSParticipantInfoPart() {}

    virtual ~StaticRTPSParticipantInfoPart() {}

    //! RTPS PArticipant name
    std::string m_RTPSParticipantName;
    //! Vector of ReaderProxyData pointer
    std::vector<ReaderProxyDataPart*> m_readers;
    //! Vector of ReaderProxyData pointer
    std::vector<WriterProxyDataPart*> m_writers;
};

class XMLEndpointParserPart {
 public:
    XMLEndpointParserPart();
    virtual ~XMLEndpointParserPart();
    /**
     * Load the XML file
     * @param filename Name or data of the file to load and parse.
     * The string could contain a filename (file://) or the XML content directly (data://), filename
     * assumed if neither
     * @return True if correct.
     */
    XMLP_ret loadXMLFile(std::string& filename);

    XMLP_ret loadXMLFile(std::string& filename, std::string& participantName);
    /**
     * Load the XML node
     * @param doc Node to parse.
     * @return True if correct.
     */
    XMLP_ret loadXMLNode(tinyxml2::XMLDocument& doc);

    void loadXMLParticipantEndpoint(tinyxml2::XMLElement* xml_endpoint, StaticRTPSParticipantInfoPart* pdata);

    /**
     * Load a Reader endpoint.
     * @param xml_endpoint Reference of a tree child for a reader.
     * @param pdata Pointer to the RTPSParticipantInfo where the reader must be added.
     * @return True if correctly added.
     */
    XMLP_ret loadXMLReaderEndpoint(tinyxml2::XMLElement* xml_endpoint, StaticRTPSParticipantInfoPart* pdata);
    /**
     * Load a Writer endpoint.
     * @param xml_endpoint Reference of a tree child for a writer.
     * @param pdata Pointer to the RTPSParticipantInfo where the reader must be added.
     * @return True if correctly added.
     */
    XMLP_ret loadXMLWriterEndpoint(tinyxml2::XMLElement* xml_endpoint, StaticRTPSParticipantInfoPart* pdata);

    std::vector<StaticRTPSParticipantInfoPart*>& getRTPSParticipantsInfo() { return m_RTPSParticipants; }

 private:
    std::set<uint32_t> m_entityIds;

    std::vector<StaticRTPSParticipantInfoPart*> m_RTPSParticipants;
};

}  // namespace xmlparser
}  // namespace vbsutil

#endif
